package com.example.myapplication.framework;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import com.example.myapplication.R;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.Socket;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.ObservableTransformer;

public class MainActivity extends NetworkBaseActivity {
    private TextView name;
    private TextView age;
    private Observable observable;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        logIn();
    }

    private void signUp() {
        Map<String, String> params = new HashMap<>();
        params.put("phoneNum", "15776803148");
        params.put("name", "qian");
        params.put("password", "123");


        observable = RetroFactory.getInstance().signUp(params);
        observable.compose(composeFunction).subscribe(new BaseObserver<String>(MainActivity.this) {
            @Override
            void onHandleSuccess(String operationState) {
                if(operationState.equals("SUCCESS")){
                    Log.e("signUp", "注册成功");
                }else{
                    Log.e("signUp", "注册失败");
                }
            }
        });
    }

    private void logIn(){
        Map<String, String> params = new HashMap<>();
        params.put("phoneNum", "15776803148");
        params.put("password", "123");

        observable = RetroFactory.getInstance().logIn(params);
        observable.compose(composeFunction).subscribe(new BaseObserver<String>(MainActivity.this) {
            @Override
            void onHandleSuccess(String token) {
                Log.e("logIn", "登陆成功"+token);
            }
        });
    }

//    private void test() throws IOException {
//        Map<String, String> map = new HashMap<String, String>();
//        map.put("phoneNum", "123");
//        map.put("name", "gesanri");
//
//        observable = RetroFactory.getInstance().getUser();
//        observable.compose(composeFunction).subscribe(new BaseObserver<User>(MainActivity.this) {
//            @Override
//            void onHandleSuccess(User user) {
//                Log.e("aaa","成功++++++++++++++++++++++++++++++++++++++");
//            }
//        });
//    }
}

